package com.zjeav.lingjiao.ui.personCenter;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.dalimao.corelibrary.swipeback.SwipeBackActivity;
import com.zjeav.lingjiao.R;
import com.zjeav.lingjiao.base.baseBean.BaseActivity;
import com.zjeav.lingjiao.base.baseBean.Result;
import com.zjeav.lingjiao.base.request.SuggestRequest;
import com.zjeav.lingjiao.base.utils.ErrorUtils;
import com.zjeav.lingjiao.ui.personCenter.view.SysContract;
import com.zjeav.lingjiao.ui.presenter.SysPresenter;

public class FeedbackActivity extends SwipeBackActivity implements View.OnClickListener, SysContract.FeedBackView {
    EditText feedback_ed;
    TextView submit_txt;
    SysPresenter sysPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.feedfbacklayout);
        init();
    }

    private void init() {
        feedback_ed = findViewById(R.id.feedback_ed);
        submit_txt = findViewById(R.id.submit_txt);
        submit_txt.setOnClickListener(this);
        sysPresenter = new SysPresenter(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.submit_txt:
                if (!"".equals(feedback_ed.getText().toString())) {
                    SuggestRequest suggestRequest = new SuggestRequest(feedback_ed.getText().toString());
                    sysPresenter.feedback(suggestRequest);
                } else {
                    Toast.makeText(this, "请输入反馈意见!", Toast.LENGTH_SHORT).show();
                }
                break;
        }
    }

    @Override
    public void FeedBackSuccess(Result result) {
        Toast.makeText(this, "尊敬的用户，感谢您提出的宝贵意见。我们将尽快处理，谢谢！", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void showError(Throwable throwable, String message) {
        Toast.makeText(this, ErrorUtils.showError(throwable, message), Toast.LENGTH_SHORT).show();
    }
}
